package com.sinosoft.bee.services.proposal.mapper;

import com.sinosoft.bee.services.proposal.entity.proposal.ProposalTrack;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: TrickerL
 * @Description: bee
 * @Date: Create in 15:38 2018/5/16
 * @Modified By:
 */
@Mapper
@Repository
public interface ProposalTrackMapper {

    /**
     * 向轨迹表增加数据
     * @param proposalTrack
     * @return
     */
    @Insert("INSERT INTO proposal_track (\n" +
            "  proposal_id,\n" +
            "  send_time,\n" +
            "  create_user,\n" +
            "  gmt_create,\n" +
            "  modified_user,\n" +
            "  gmt_modified,\n" +
            "  is_deleted\n" +
            ")\n" +
            "VALUES\n" +
            "  (\n" +
            "    #{proposalId},\n" +
            "    #{sendTime},\n" +
            "    #{createUser},\n" +
            "    #{gmtCreate},\n" +
            "    #{modifiedUser},\n" +
            "    #{gmtModified},\n" +
            "    #{isDeleted}\n" +
            "  );\n")
    Integer insertProposalTrack(ProposalTrack proposalTrack);

    /**
     * 删除轨迹表
     * @param proposalTrack
     * @return
     */
    @Delete("delete from proposal_track where proposal_id=#{proposalId};")
    Integer deleteProposalTrack(ProposalTrack proposalTrack);

    /**
     * 查询所有轨迹表
     * @return
     */
    @Results(id = "Track", value = {
            @Result(property = "proposalId", column = "proposal_id"),
            @Result(property = "sendTime", column = "send_time"),
            @Result(property = "createUser", column = "create_user"),
            @Result(property = "gmtCreate", column = "gmt_create"),
            @Result(property = "modifiedUser", column = "modified_user"),
            @Result(property = "gmtModified", column = "gmt_modified"),
            @Result(property = "isDeleted", column = "is_deleted")
    })
    @Select("select send_time,proposal_id from proposal_track")
    List<ProposalTrack> selectAllTrack();

    /**
     * 修改is_deleted by proposal_id
     */
    @Update("update proposal_track set is_deleted=#{isDeleted} where proposal_id=#{proposalId}")
    void updateById(ProposalTrack proposalTrack);
}
